package com.stars.system.fitness.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.stars.system.fitness.domain.FitnessRecord;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.stars.system.fitness.service.IFitnessRecordService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fitnessController
 * 
 * @author shuaibizhe
 * @date 2022-06-21
 */
@RestController
@RequestMapping("/fitness/record")
public class FitnessRecordController extends BaseController
{
    @Autowired
    private IFitnessRecordService fitnessService;

    /**
     * 查询fitness列表，表格样
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:list')")
    @GetMapping("/listTable")
    public TableDataInfo listTable(FitnessRecord fitness)
    {
        startPage();
        fitness.setCreateUser(getUserId());
        List<Map> list = fitnessService.selectFitnessList(fitness, "table");
        return getDataTable(list);
    }

    /**
     * 查询fitness列表，日历样
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:list')")
    @GetMapping("/listCalendar")
    public TableDataInfo listCalendar(FitnessRecord fitness)
    {
        fitness.setCreateUser(getUserId());
        List<String> list = fitnessService.selectFitnessList(fitness, "calendar");
        return getDataTable(list);
    }

    /**
     * 查询fitness列表，折叠面板样
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(FitnessRecord fitness)
    {
        fitness.setCreateUser(getUserId());
        List<Map> list = fitnessService.selectFitnessList(fitness, "collapse");
        return getDataTable(list);
    }

//    /**
//     * 导出fitness列表
//     */
//    @PreAuthorize("@ss.hasPermi('fitness:record:export')")
//    @Log(title = "fitness", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Fitness fitness)
//    {
//        List<Fitness> list = fitnessService.selectFitnessList(fitness);
//        ExcelUtil<Fitness> util = new ExcelUtil<Fitness>(Fitness.class);
//        util.exportExcel(response, list, "fitness数据");
//    }

    /**
     * 获取fitness详细信息
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fitnessService.selectFitnessById(id));
    }

    /**
     * 新增fitness
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:add')")
    @Log(title = "fitness", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FitnessRecord fitness)
    {
        fitness.setCreateUser(getUserId());
        return toAjax(fitnessService.insertFitness(fitness));
    }

    /**
     * 修改fitness
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:edit')")
    @Log(title = "fitness", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FitnessRecord fitness)
    {
        return toAjax(fitnessService.updateFitness(fitness));
    }

    /**
     * 删除fitness
     */
    @PreAuthorize("@ss.hasPermi('fitness:record:remove')")
    @Log(title = "fitness", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fitnessService.deleteFitnessByIds(ids));
    }

    /**
     * 修改fitness完成状态
     */
    @Log(title = "fitness", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public String updateStatus(@RequestBody FitnessRecord fitness)
    {
        fitnessService.updateFitness(fitness);
        return fitness.getDate();
    }
}
